<template>
	<view>
		<u-cell-group style="background: #fff;">
			<u-cell-item v-for="(item,index) in Data" @click="click(index)" :title="item" :arrow="true"
				arrow-direction="right"></u-cell-item>
		</u-cell-group>
		<u-cell-group style="background: #fff; margin-top: 10px;">
			<u-cell-item v-for="(item,index) in Data2" @click="change(index)" :title="item" :arrow="true"
				arrow-direction="right"></u-cell-item>
		</u-cell-group>

		<view
			style="position: fixed; z-index: 1; width: 100%; line-height: 46px; color: #FA9700; background: #fff; bottom: 0; left: 0; text-align: center;"
			@click="eaitLogin">
			退出登录
		</view>
		<!-- 退出登录弹框 -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Data: ['修改绑定手机号', '修改登录密码', '修改支付密码'],
				Data2: ['隐私协议', '用户协议', '关于我们', '清除缓存'],
			}
		},
		methods: {
			click(e) {
				console.log(e)
				var url
				switch (e) {
					case 0:
						url = '/pages/set/message/message?title=修改绑定手机号&type=0'
						break
					case 1:
						url = '/pages/set/message/message?title=修改登录密码&type=1'
						break
					case 2:
						url = '/pages/set/message/message?title=修改支付密码&type=2'
						break
				}
				uni.navigateTo({
					url: url
				})
			},
			change(e) {
				console.log(e)
				var url
				switch (e) {
					case 0:
						url = '/pages/public/public?title=隐私协议&id=1'
						break
					case 1:
						url = '/pages/public/public?title=用户协议&id=4'
						break
					case 2:
						url = '/pages/public/public?title=关于我们&id=2'
						break
					case 3:
						uni.showModal({
							content: '是否清理缓存',
							success: (res) => {
								// console.log(res)
								if (res.confirm) {
									// #ifdef APP-PLUS
									var self = this;
									//使用plus.cache.clear 清除应用中的缓存数据
									plus.cache.clear(function() {
										uni.showToast({
											title: '清除成功!',
											icon: 'none',
										})
									});
									// #endif
								}
							}
						})

						break
				}
				uni.navigateTo({
					url: url
				})
			},
			login() {
				const userID = uni.getStorageSync('userID')
				const userSig = uni.getStorageSync('userSig')
				console.log('腾讯云登出', userID)
			
				uni.$TUIKit.logout({
						userID,
						userSig
					})
					.then(function(imResponse) {
						console.log('登出成功', imResponse.data); // 登录成功
						// if (imResponse.data.repeatLogin === true) {
						// 	// 标识帐号已登录，本次登录操作为重复登录。v2.5.1 起支持
						// 	console.log(imResponse.data.errorInfo);
						// }
					})
					.catch(function(imError) {
						console.warn('login error:', imError); // 登录失败的相关信息
					})
			
			},
			eaitLogin() {
				var that=this
				// 退出登录
				uni.showModal({
					content: '确定要退出当前账号吗？',
					success: function(res) {
						if (res.confirm) {
							uni.clearStorageSync(); //清除所有的缓存数据
							uni.reLaunch({
								url: '/pages/login/login'
							})
							that.login()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		}
	}
</script>

<style>
	page {
		background: #f0f0f0;
	}
</style>
